﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_pages_SanKetQuaPV_edit : System.Web.UI.Page
{
    public string masan;
    public string tensan;
    public string soVLT;
    public string soNTV;
    public string ma_vlt;
    public string ma_ntd;
    public string ma_ntv;
    public string ten_ntv;
    public string ten_vlt;
    public string ten_ntd;
    public Common comm = new Common();
    SanGDVL sanComm = new SanGDVL();
    public DataTable dtt_san;
    protected void Page_Load(object sender, EventArgs e)
    {
        masan = Request.QueryString["sid"];

        if (Session["SanNTD"] == null) Response.Redirect("SanDangNhap.aspx?sid=" + masan);
        if ((bool)Session["SanNTD"] == false) Response.Redirect("SanDangNhap.aspx?sid=" + masan);


        string sql = "SELECT * FROM sangiaodich "
                   + " inner join TrungTamViecLam on TrungTamViecLam.ma_trung_tam = sangiaodich.ma_trung_tam "
                   + " WHERE  ma_san =  " + masan; ;
        dtt_san = comm.getDataTable(sql);

        if (dtt_san.Rows.Count == 0)
        {

            Response.Redirect("SanNotFound.aspx");

        }
        else if (Convert.ToInt32(dtt_san.Rows[0]["kich_hoat"]) == 1)
        {

            tensan = "ĐANG MỞ";
            soVLT = sanComm.SoLuongVLT(masan);
            soNTV = sanComm.SoLuongNTV(masan);

            ma_ntv = Request.QueryString["mantv"];
            ma_vlt = Request.QueryString["mavlt"];

            txt_tenungvien.Text = new NguoiTimViecCommon().getTenNTV(ma_ntv);
            txt_tuyendung.Text = comm.getDataTable("select top 1 tieu_de_ho_so from ViecLamTrong_ho_so_tuyen_dung where ma_ho_so = " + ma_vlt).Rows[0][0].ToString();



            ma_ntd = new NhaTuyenDungCommon().getMaNTD(Session["SanNTDuser"].ToString());
            ten_ntd = NhaTuyenDungCommon.getTenDoanhNghiep(ma_ntd);

            if (!IsPostBack)
            {
                if (sanComm.KetquaSan(masan, ma_vlt, ma_ntv))
                {

                    DataTable dtt_san1 = comm.getDataTable("Select * from SanGiaoDich_ket_qua_phong_van where ma_san = " + masan + " and ma_vlt =" + ma_vlt + " and ma_ntv = " + ma_ntv);
                    if (dtt_san.Rows.Count > 0)
                    {

                        txt_mota.Text = dtt_san1.Rows[0]["ghi_chu"].ToString();
                      //  cbb_ketqua.Items.FindByValue(dtt_san1.Rows[0]["ket_qua"].ToString()).Selected= true;
                        date1.SelectedDate = Convert.ToDateTime(dtt_san1.Rows[0]["ngay_phong_van"]);
                        if (Convert.ToBoolean(dtt_san1.Rows[0]["ket_qua"]) == true)
                            cbb_ketqua.SelectedIndex = 0;
                        else
                            cbb_ketqua.SelectedIndex = 1;
                    }
                }
            }
        }


    }
    public string mess = "";
    protected void Btn_dangky_Click(object sender, EventArgs e)
    {


        //bool res = sanComm.SuaKetQuaTuyenDung(masan, ma_vlt, ma_ntv, ma_ntd, date1.SelectedDate.GetValueOrDefault().ToString("MM-dd-yyyy"), comm.TextFormat(txt_mota.Text), cbb_ketqua.SelectedValue);
		bool res = false;
        try
        {

            int idx = comm.execNoneQuery("UPDATE [SanGiaoDich_ket_qua_phong_van] SET Ket_qua = " + cbb_ketqua.SelectedValue + " , ngay_phong_van = '" + date1.SelectedDate.GetValueOrDefault().ToString("MM-dd-yyyy") + "' , ghi_chu = N'" + comm.TextFormat(txt_mota.Text) + "' WHERE ma_san =" + masan + " and ma_ntv=" + ma_ntv + " and ma_vlt = " + ma_vlt + "");
            if (idx > 0) res = true;
            
        }
        catch (Exception)
        {
            throw;
            
        }


        if (res)
            mess = "<script type='text/javascript' > alert('Nhập Thông Tin Thành Công!'); window.location.href = 'SanNhaTuyenDung.aspx?sid=" + masan + "'  </script>";
        else
            mess = "<script type='text/javascript' > alert('Không thể Nhập Thông Tin!'); </script>";
    }
}
